import os

def main():
    makeLatex()


    return

def makeLatex():
    path = './scripts/docOriginal.tex'
    fp = open(path)

    for line in fp:
        if 'makeSrcLatex' in line:
            makeSrcLatex()
        elif 'makeIncLatex' in line:
            makeIncLatex()
        else:
            print line[:len(line)-1]

    return

def makeIncLatex():
    print '\subsection{Headers}'
    path = './include/'
    dirList=os.listdir(path)

    last = '\n'

    for fName in dirList:

        if '.svn' not in fName and '~' not in fName and 'pcihdr.h' not in fName:

            if 'key_layouts.h' in fName:
                print '\subsubsection{key\_layouts.h}'
            else:
                print '\subsubsection{' + fName + '}'

            print '\\footnotesize'
            print '\\begin{verbatim}'

            pf  = open(path + fName)
            for line in pf:
                if line[0] == '\n' and last[0] == '\n':
                    last = line
                else:
                    last = line
                    print line[:len(line)-1]

            print '\end{verbatim}'
            print '\\normalsize'

    print '\subsubsection{pcihdr.h}'
    print '\\footnotesize'
    print '\\begin{verbatim}'
    print 'Archivo con la estructura de los pci.'
    print 'No se imprime.'
    print '\end{verbatim}'
    print '\\normalsize'
    return

def makeSrcLatex():
    print '\subsection{Sources}'
    path = './src/'
    dirList=os.listdir(path)

    last = '\n'

    for fName in dirList:

        if '.svn' not in fName and '~' not in fName:
            print '\subsubsection{' + fName + '}'
            print '\\footnotesize'
            print '\\begin{verbatim}'

            pf  = open(path + fName)
            for line in pf:
                if line[0] == '\n' and last[0] == '\n':
                    last = line
                else:
                    last = line
                    print line[:len(line)-1]

            print '\end{verbatim}'
            print '\\normalsize'

    return

if __name__ == '__main__':
   main()